import global from 'global';
cc.Class({
    extends: cc.Component,

    properties: {
		gtypenode:cc.Node,
		qipannode:cc.Node,
		alertnode:cc.Node,
		qipan:cc.Prefab,
		alertcell:cc.Prefab,
    },

    onLoad () {
		//逻辑棋盘初始化（零化）
		global.rolecolor = 1;
		
		global.qipanarrinit();
		global.initlogicqipan();
	},

    start () {
		cc.director.on('pvp',(e)=>{
			global.rolecolor = e.color;
			global.initlogicqipan();
			let qipan = cc.instantiate(this.qipan);
            qipan.parent = this.qipannode;
			
		},this);
		//监听所有的alert消息
		cc.director.on('alert',(e)=>{
			if(global.minitips >=4){
				this.alertnode.removeAllChildren();
			}
			let alertcell = cc.instantiate(this.alertcell);
			alertcell.parent = this.alertnode;
			cc.director.emit('alerttext',e);
		},this);
		
    },
    btnClick(event,customData){
        switch(customData){
            case 'renji'://人机对战，缺AI不做
				//逻辑准备
				global.rolecolor = 1;
				global.initlogicqipan();
				//以下是ui操作
				let qipan = cc.instantiate(this.qipan);
				qipan.parent = this.qipannode;
				
				break;
            case 'pipei'://匹配模式，默认
				
				break;
            case 'xinrenstart':
            
            break;
				default:
            
            break;
            
        }
    },
 
    // update (dt) {},
});
